package com.fgw.controller.backend;

import com.fgw.common.Const;
import com.fgw.common.ResponseCode;
import com.fgw.common.ServerResponse;
import com.fgw.pojo.Pxtonzhi;
import com.fgw.pojo.Teacher;
import com.fgw.service.IPxtonzhiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by lcx on 2017/9/21.
 */
@Controller
@RequestMapping("/admin/Workbench/")
public class WorkbenchAdminController {

    @Autowired
    private IPxtonzhiService iPxtonzhiService;

    /**
     * 起草文件的培训通知添加
     * @param session
     * @param pxtonzhi
     * @return
     */
    @RequestMapping(value = "savetrainingInform.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse trainingInformSave(HttpSession session, Pxtonzhi pxtonzhi) {

        Teacher teacher = (Teacher) session.getAttribute(Const.CURRENT_USER);
        if (teacher == null) {
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "用户未登录请先登录");
        } else {

            return iPxtonzhiService.savePxtonzhi(pxtonzhi, teacher);

        }
    }

    /**
     *  待办文件培训通知
     *
     * @param session
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "pxtonzhibench_list.do", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse pxtonzhiBenchList(HttpSession session, @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",defaultValue = "5")Integer pageSize){

        Teacher teacher = (Teacher) session.getAttribute(Const.CURRENT_USER);
        if (teacher == null) {
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), "用户未登录请先登录");
        } else {

            return iPxtonzhiService.pxtonzhiBenchList(pageNum,pageSize);

        }
    }


}
